package com.yuncheng.config;

import com.yuncheng.util.CcMinioUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CcMinioConfig {
    @Value("${yuncheng.minio.minio_url}")
    private String minioUrl;
    @Value("${yuncheng.minio.minio_name}")
    private String minioName;
    @Value("${yuncheng.minio.minio_pass}")
    private String minioPass;
    @Value("${yuncheng.minio.bucketName}")
    private String bucketName;

    public CcMinioConfig() {
    }

    @Bean
    public void ccInitMinio() {
        if (!this.minioUrl.startsWith("http")) {
            this.minioUrl = "http://" + this.minioUrl;
        }

        if (!this.minioUrl.endsWith("/")) {
            this.minioUrl = this.minioUrl.concat("/");
        }

        CcMinioUtil.setMinioUrl(this.minioUrl);
        CcMinioUtil.setMinioName(this.minioName);
        CcMinioUtil.setMinioPass(this.minioPass);
        CcMinioUtil.setBucketName(this.bucketName);
    }
}
